package top.zhangjianyong.tools.service.mybatis.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.zhangjianyong.tools.entity.Area;
import top.zhangjianyong.tools.mapper.AreaMapper;
import top.zhangjianyong.tools.service.mybatis.IAreaService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zhangjianyong
 * @since 2024/9/29 上午10:58
 */
@Service
public class IAreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {
    @Override
    public List<Area> listByCode(List<String> areas) {
        return lambdaQuery()
                .in(Area::getCode, areas)
                .list();
    }

    @Override
    public List<Area> listByPcode(Long code) {
        return lambdaQuery()
                .eq(Area::getPcode, code)
                .list();
    }

    @Override
    public List<Area> listByPrefix(List<String> prefix) {
        List<Area> list = new ArrayList<>();
        for (String code : prefix) {
            List<Area> areas = lambdaQuery()
                    .likeRight(Area::getCode, code)
                    .list();
            list.addAll(areas);

        }
        return list;
    }

    @Override
    public Area getByCode(String code) {
        return lambdaQuery()
                .eq(Area::getCode, code)
                .one();
    }

    @Override
    public List<Area> listByLevel(int level) {
        return lambdaQuery().eq(Area::getLevel, level).list();
    }


}
